package cn.t.service.sku;


import cn.t.core.mode.PageQueryDTO;
import cn.t.core.service.ServiceImpl;
import cn.t.model.sku.CategoryDO;
import cn.t.repository.sku.CategoryRepository;
import cn.t.request.CategoryReq;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 商品类别表(Category)领域服务
 *
 * @author t
 * @since 2024-06-11 10:35:25
 */
@Slf4j
@Service
@AllArgsConstructor
public class CategoryService extends ServiceImpl<CategoryDO, CategoryRepository> {

    public List<CategoryDO> queryCategoryByPage(PageQueryDTO<CategoryReq> req, String field, String desc) {
        return repository.queryCategoryByPage(req, field, desc);
    }

    public Long queryCategoryCount(CategoryReq param) {
        return repository.queryCategoryCount(param);
    }

    public Map<Long, String> findNameByIds(List<Long> ids) {
        List<CategoryDO> list = repository.findNameByIds(ids);
        return list.stream().collect(Collectors.toMap(CategoryDO::getId, CategoryDO::getCategoryName));
    }

}
